package com.renwei.yunlong.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.renwei.yunlong.R;
import com.renwei.yunlong.base.BaseActivity;
import com.renwei.yunlong.bean.RegisterBean;
import com.renwei.yunlong.http.HttpPresenter;
import com.renwei.yunlong.http.HttpTaskListener;
import com.renwei.yunlong.utils.ToastUtil;
import com.zyf.fwms.commonlibrary.http.Api;
import com.zyf.fwms.commonlibrary.utils.AutoUtils;
import com.zyf.fwms.commonlibrary.utils.CommonUtils;
import com.zyf.fwms.commonlibrary.utils.StatusBarUtil;

import butterknife.Bind;
import butterknife.ButterKnife;

import static android.R.attr.password;
import static com.renwei.yunlong.R.id.cancel_action;
import static com.renwei.yunlong.R.id.iv_back;

/**
 * 意见反馈--页面
 * <p>
 * Created by Administrator on 2017/8/25.
 */

public class FeedbackActivity extends BaseActivity implements View.OnClickListener,HttpTaskListener {

    @Bind(iv_back)
    ImageView ivBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_edit)
    TextView tvEdit;
    @Bind(R.id.et_content)
    EditText etContent;//反馈内容
    @Bind(R.id.et_phone)
    EditText etPhone;//手机号

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_feedback);
        ButterKnife.bind(this);
        StatusBarUtil.setColor(this, CommonUtils.getColor(this, R.color.title_color), 0);
        //屏幕自适配
        AutoUtils.setSize(this, false, 720, 1280);
        AutoUtils.auto(this);

        initData();
    }

    private void initData() {
        ivBack.setVisibility(View.VISIBLE);
        tvEdit.setVisibility(View.VISIBLE);
        tvTitle.setText("意见反馈");
        tvEdit.setText("提交");
        ivBack.setOnClickListener(this);
        tvEdit.setOnClickListener(this);
    }

    //业主意见反馈
    private void ownerFeedbackHttp(String jsonBean){
        HttpPresenter hp = new HttpPresenter(this);
        hp.setUrl(Api.OWNER_FEEDBACK_URL);
        hp.setshowDialogcontent("正在提交");
        hp.setRequsetId(1);
        hp.putParam("jsonBean",jsonBean);
        hp.setCallBack(this);
        hp.post();
    }

    //服务商意见反馈
    private void serviceFeedbackHttp(String jsonBean){
        HttpPresenter hp = new HttpPresenter(this);
        hp.setUrl(Api.SERVICE_FEEDBACK_URL);
        hp.setshowDialogcontent("正在提交");
        hp.setRequsetId(1);
        hp.putParam("jsonBean", jsonBean);
        hp.setCallBack(this);
        hp.post();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_edit://提交
                String content = etContent.getText().toString().trim();
                String phone = etPhone.getText().toString().trim();

                String companyCode = "20170905-143432-71";//用户信息对象中
                String companyType = "1";

                if (!TextUtils.isEmpty(content) && !TextUtils.isEmpty(phone)){
                    String jsonBean="{ticklIntro:\""+content+"\",companyCode:\""+companyCode+"\",userName:\""+phone+"\",companyType:\""+companyType+"\"}";

                    Log.e("业主意见反馈:",jsonBean);

                    ownerFeedbackHttp(jsonBean);

                }else {
                    ToastUtil.showShort(this,"不能为空");
                }
                break;
            default:
                break;
        }
    }

    @Override
    public void onSuccess(int requestId, String result) {
        switch (requestId){
            case 1:
                RegisterBean registerBean = new Gson().fromJson(result, RegisterBean.class);
                if (registerBean.getMessage().getCode() == 200){//成功  200
                    ToastUtil.showShort(this,"提交成功");
                    finish();
                }
                break;
            case 2:
                break;
            case 3:
                break;
            default:
                break;
        }
    }

    @Override
    public void onException(int requestId, String code) {

    }
}
